package com.woniuxy.service.impl;

import com.woniuxy.dao.DrugDao;
import com.woniuxy.dao.DrugOrderItemDao;
import com.woniuxy.dao.DrugPeopleDao;
import com.woniuxy.entity.DrugKind;
import com.woniuxy.entity.DrugOrderItem;
import com.woniuxy.entity.DrugPeople;
import com.woniuxy.service.DrugStoreItemService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DrugStoreItemServiceImpl implements DrugStoreItemService {

    @Resource
    DrugOrderItemDao drugOrderItemDao;
    @Resource
    DrugDao drugDao;
    @Resource
    DrugPeopleDao drugPeopleDao;

//    药品明细获取
    @Override
    public List<DrugOrderItem> getAllItem(Integer repertoryId) {
        List<DrugOrderItem> drugOrderItems=drugOrderItemDao.selectAllOrderItem(repertoryId);

        for(DrugOrderItem di : drugOrderItems){

            if(di.getDrugRepertory().getRepertoryStatus()==2){
                di.getDrugRepertory().setStatus("无货，请采购");
            }else if(di.getDrugRepertory().getRepertoryStatus()==1){
                di.getDrugRepertory().setStatus("有货");
            }else{
                di.getDrugRepertory().setStatus("过期，请重新采购");
            };

            DrugKind drugKind= drugDao.selectKing(di.getKindId());
            di.getDrugRepertory().setKind(drugKind.getKindName());

            if(di.getDrugOrder().getOrderStatus()==4){
                di.getDrugOrder().setStatus("采购入库");
            }else if(di.getDrugOrder().getOrderStatus()==5){
                di.getDrugOrder().setStatus("其他入库");
            }else{
                di.getDrugOrder().setStatus("科室入库");
            };

            double amount=di.getRepertorySum()*di.getDrugRepertory().getRepertoryPrice();
            di.setAmount(amount);

            DrugPeople drugPeople=drugPeopleDao.selectName(di.getDrugOrder().getPeopleId());
            di.getDrugOrder().setPeopleName(drugPeople.getPeopleName());
        }

        return drugOrderItems;
    }
}
